package cn.edu.ecust.common.util;

import cn.edu.ecust.common.constant.HttpRespCode;
import com.fasterxml.jackson.annotation.JsonFormat;

import java.util.Date;

/**
 * @author cjj
 * @date 2023/08/30 01:46
 * @description 封装返回数据类
 **/
public class Resp<T> {
    private static final long serialVersionUID = -8660197629749596025L;
    protected String resCode;
    protected String resMsg;
    protected Date resTime;
    protected T data;

    public Long getResTime() {
        return this.resTime == null ? 0L : this.resTime.getTime();
    }

    public void setResTime(Date resTime) {
        this.resTime = resTime;
    }

    public Resp() {
    }

    public Resp(HttpRespCode resCode) {
        this.resCode = resCode.getCode();
        this.resMsg = resCode.getText();
        this.resTime = new Date();
    }


    public Resp(HttpRespCode resCode, T data) {
        this.resCode = resCode.getCode();
        this.resMsg = resCode.getText();
        this.resTime = new Date();
        this.data = data;
    }

    public Resp(String resCode, String resMsg) {
        this.resCode = resCode;
        this.resMsg = resMsg;
        this.resTime = new Date();
    }

    public Resp(String resCode, String resMsg, Date resTime) {
        this.resCode = resCode;
        this.resMsg = resMsg;
        this.resTime = resTime;
    }

    public Resp(String resCode, String resMsg, T data) {
        this.resCode = resCode;
        this.resMsg = resMsg;
        this.data = data;
        this.resTime = new Date();
    }

    public Resp(String resCode, String resMsg, Date resTime, T data) {
        this.resCode = resCode;
        this.resMsg = resMsg;
        this.resTime = resTime;
        this.data = data;
    }


    public String getResCode() {
        return this.resCode;
    }

    public void setResCode(String resCode) {
        this.resCode = resCode;
    }

    public String getResMsg() {
        return this.resMsg;
    }

    public void setResMsg(String resMsg) {
        this.resMsg = resMsg;
    }

    public T getData() {
        return this.data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "Resp(resCode=" + this.getResCode() + ", resMsg=" + this.getResMsg() + ", resTime=" + this.getResTime() + ", data=" + this.getData() + ")";
    }
}
